package c.c.a;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.huawei.hms.jos.games.player.GameTrialConstant;
import java.util.HashMap;
import org.json.JSONObject;

public class u {
    public static int d;
    public static final HashMap<String, s> e;
    public final g2 a;
    public final c b;
    public final a c;

    public static class a extends SQLiteOpenHelper {
        public a(Context context, String str, CursorFactory cursorFactory, int i) {
            super(context, str, null, i);
        }

        public void onCreate(SQLiteDatabase sQLiteDatabase) {
            try {
                sQLiteDatabase.beginTransaction();
                for (s h : u.e.values()) {
                    String h2 = h.h();
                    if (h2 != null) {
                        sQLiteDatabase.execSQL(h2);
                    }
                }
                sQLiteDatabase.setTransactionSuccessful();
                try {
                    sQLiteDatabase.endTransaction();
                } catch (Exception e) {
                    m0.b(e);
                }
            } catch (Throwable th) {
                try {
                    sQLiteDatabase.endTransaction();
                } catch (Exception e2) {
                    m0.b(e2);
                }
                throw th;
            }
        }

        public void onDowngrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
            onUpgrade(sQLiteDatabase, i, i2);
        }

        public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("onUpgrade, ");
            stringBuilder.append(i);
            stringBuilder.append(", ");
            stringBuilder.append(i2);
            String str = "TeaLog";
            Log.i(str, stringBuilder.toString(), null);
            try {
                sQLiteDatabase.beginTransaction();
                for (s sVar : u.e.values()) {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    stringBuilder2.append("DROP TABLE IF EXISTS ");
                    stringBuilder2.append(sVar.i());
                    sQLiteDatabase.execSQL(stringBuilder2.toString());
                }
                sQLiteDatabase.setTransactionSuccessful();
                try {
                    sQLiteDatabase.endTransaction();
                } catch (Exception e) {
                    m0.b(e);
                }
            } catch (Throwable th) {
                try {
                    sQLiteDatabase.endTransaction();
                } catch (Exception e2) {
                    m0.b(e2);
                }
                throw th;
            }
            onCreate(sQLiteDatabase);
        }
    }

    static {
        int i = b0.o;
        HashMap hashMap = new HashMap();
        e = hashMap;
        hashMap.put("page", new a0());
        hashMap.put(GameTrialConstant.NOTIFY_EVENT_KEY, new v());
        hashMap.put("eventv3", new x(null, false, null));
        hashMap.put("launch", new y());
        hashMap.put("terminate", new d0());
        hashMap.put("pack", new z());
        hashMap.put("event_misc", new w("", new JSONObject()));
        hashMap.put("succEvent", new b0());
    }

    public u(Application application, c cVar, g2 g2Var) {
        this.c = new a(application, "bd_embed_tea_agent.db", null, 29);
        this.b = cVar;
        this.a = g2Var;
    }

    /* JADX WARNING: Removed duplicated region for block: B:47:0x0019 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:36:0x00b7  */
    /* JADX WARNING: Removed duplicated region for block: B:32:0x0084  */
    /* JADX WARNING: Removed duplicated region for block: B:36:0x00b7  */
    /* JADX WARNING: Removed duplicated region for block: B:47:0x0019 A:{SYNTHETIC} */
    public final int a(c.c.a.s[] r17, int r18, android.database.sqlite.SQLiteDatabase r19, java.lang.String r20, org.json.JSONArray[] r21) {
        /*
        r16 = this;
        r1 = r16;
        r2 = r17;
        r3 = r19;
        r4 = r20;
        r0 = 0;
    L_0x0009:
        r5 = 0;
        r6 = r18;
        if (r0 >= r6) goto L_0x0014;
    L_0x000e:
        r7 = r0 + 1;
        r21[r0] = r5;
        r0 = r7;
        goto L_0x0009;
    L_0x0014:
        r6 = 200; // 0xc8 float:2.8E-43 double:9.9E-322;
        r6 = r0;
        r7 = 200; // 0xc8 float:2.8E-43 double:9.9E-322;
    L_0x0019:
        if (r7 <= 0) goto L_0x00c3;
    L_0x001b:
        r0 = r2.length;
        if (r6 >= r0) goto L_0x00c3;
    L_0x001e:
        r8 = r2[r6];
        r9 = ", ";
        r10 = new org.json.JSONArray;
        r10.<init>();
        r0 = r1.b(r8, r4, r7);	 Catch:{ all -> 0x007b }
        r13 = r3.rawQuery(r0, r5);	 Catch:{ all -> 0x007b }
        r14 = 0;
    L_0x0031:
        r0 = r13.moveToNext();	 Catch:{ all -> 0x0078 }
        if (r0 == 0) goto L_0x0067;
    L_0x0037:
        r8.a(r13);	 Catch:{ all -> 0x0078 }
        r0 = c.c.a.m0.b;	 Catch:{ all -> 0x0078 }
        if (r0 == 0) goto L_0x0058;
    L_0x003e:
        r0 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0078 }
        r0.<init>();	 Catch:{ all -> 0x0078 }
        r11 = "queryEvnetInner, ";
        r0.append(r11);	 Catch:{ all -> 0x0078 }
        r0.append(r4);	 Catch:{ all -> 0x0078 }
        r0.append(r9);	 Catch:{ all -> 0x0078 }
        r0.append(r8);	 Catch:{ all -> 0x0078 }
        r0 = r0.toString();	 Catch:{ all -> 0x0078 }
        c.c.a.m0.a(r0, r5);	 Catch:{ all -> 0x0078 }
    L_0x0058:
        r0 = r8.j();	 Catch:{ all -> 0x0078 }
        r10.put(r0);	 Catch:{ all -> 0x0078 }
        r11 = r8.a;	 Catch:{ all -> 0x0078 }
        r0 = (r11 > r14 ? 1 : (r11 == r14 ? 0 : -1));
        if (r0 <= 0) goto L_0x0031;
    L_0x0065:
        r14 = r11;
        goto L_0x0031;
    L_0x0067:
        r11 = 0;
        r0 = (r14 > r11 ? 1 : (r14 == r11 ? 0 : -1));
        if (r0 <= 0) goto L_0x0074;
    L_0x006d:
        r0 = r1.c(r8, r4, r14);	 Catch:{ all -> 0x0078 }
        r3.execSQL(r0);	 Catch:{ all -> 0x0078 }
    L_0x0074:
        r13.close();
        goto L_0x0088;
    L_0x0078:
        r0 = move-exception;
        r11 = r14;
        goto L_0x007f;
    L_0x007b:
        r0 = move-exception;
        r11 = 0;
        r13 = r5;
    L_0x007f:
        c.c.a.m0.b(r0);	 Catch:{ all -> 0x00bb }
        if (r13 == 0) goto L_0x0087;
    L_0x0084:
        r13.close();
    L_0x0087:
        r14 = r11;
    L_0x0088:
        r0 = new java.lang.StringBuilder;
        r0.<init>();
        r11 = "queryEvent, ";
        r0.append(r11);
        r0.append(r8);
        r0.append(r9);
        r8 = r10.length();
        r0.append(r8);
        r0.append(r9);
        r0.append(r14);
        r0 = r0.toString();
        c.c.a.m0.a(r0, r5);
        r21[r6] = r10;
        r0 = r21[r6];
        r0 = r0.length();
        r7 = r7 - r0;
        if (r7 <= 0) goto L_0x0019;
    L_0x00b7:
        r6 = r6 + 1;
        goto L_0x0019;
    L_0x00bb:
        r0 = move-exception;
        r2 = r0;
        if (r13 == 0) goto L_0x00c2;
    L_0x00bf:
        r13.close();
    L_0x00c2:
        throw r2;
    L_0x00c3:
        return r6;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.c.a.u.a(c.c.a.s[], int, android.database.sqlite.SQLiteDatabase, java.lang.String, org.json.JSONArray[]):int");
    }

    public final String b(s sVar, String str, int i) {
        StringBuilder g = c.b.a.a.a.g("SELECT * FROM ");
        g.append(sVar.i());
        g.append(" WHERE ");
        g.append("session_id");
        g.append("='");
        c.b.a.a.a.y(g, str, "' ORDER BY ", "local_time_ms", " LIMIT ");
        g.append(i);
        return g.toString();
    }

    public final String c(s sVar, String str, long j) {
        StringBuilder g = c.b.a.a.a.g("DELETE FROM ");
        g.append(sVar.i());
        g.append(" WHERE ");
        g.append("session_id");
        g.append("='");
        c.b.a.a.a.y(g, str, "' AND ", "local_time_ms", "<=");
        g.append(j);
        return g.toString();
    }

    /*  JADX ERROR: NullPointerException in pass: ProcessVariables
        java.lang.NullPointerException
        	at jadx.core.dex.visitors.regions.ProcessVariables.addToUsageMap(ProcessVariables.java:278)
        	at jadx.core.dex.visitors.regions.ProcessVariables.access$000(ProcessVariables.java:31)
        	at jadx.core.dex.visitors.regions.ProcessVariables$CollectUsageRegionVisitor.processInsn(ProcessVariables.java:163)
        	at jadx.core.dex.visitors.regions.ProcessVariables$CollectUsageRegionVisitor.processBlockTraced(ProcessVariables.java:129)
        	at jadx.core.dex.visitors.regions.TracedRegionVisitor.processBlock(TracedRegionVisitor.java:23)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:53)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:57)
        	at java.util.ArrayList.forEach(Unknown Source)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:57)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:57)
        	at java.util.ArrayList.forEach(Unknown Source)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:57)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:57)
        	at java.util.ArrayList.forEach(Unknown Source)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:57)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:57)
        	at java.util.ArrayList.forEach(Unknown Source)
        	at java.util.Collections$UnmodifiableCollection.forEach(Unknown Source)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:57)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:57)
        	at java.util.ArrayList.forEach(Unknown Source)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:57)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverse(DepthRegionTraversal.java:18)
        	at jadx.core.dex.visitors.regions.ProcessVariables.visit(ProcessVariables.java:183)
        	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:27)
        	at jadx.core.dex.visitors.DepthTraversal.lambda$visit$1(DepthTraversal.java:14)
        	at java.util.ArrayList.forEach(Unknown Source)
        	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:14)
        	at jadx.core.ProcessClass.process(ProcessClass.java:32)
        	at jadx.core.ProcessClass.lambda$processDependencies$0(ProcessClass.java:51)
        	at java.lang.Iterable.forEach(Unknown Source)
        	at jadx.core.ProcessClass.processDependencies(ProcessClass.java:51)
        	at jadx.core.ProcessClass.process(ProcessClass.java:37)
        	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:292)
        	at jadx.api.JavaClass.decompile(JavaClass.java:62)
        	at jadx.api.JadxDecompiler.lambda$appendSourcesSave$0(JadxDecompiler.java:200)
        */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x006c  */
    /* JADX WARNING: Removed duplicated region for block: B:29:0x0098  */
    public final org.json.JSONArray d(c.c.a.y r12, c.c.a.d0 r13, c.c.a.a0 r14, android.database.sqlite.SQLiteDatabase r15) {
        /*
        r11 = this;
        r0 = ", ";
        r1 = 1;
        r2 = new java.lang.String[r1];
        r3 = r12.c;
        r4 = 0;
        r2[r4] = r3;
        r3 = new org.json.JSONArray;
        r3.<init>();
        r5 = 0;
        r6 = 0;
        r8 = "SELECT * FROM page WHERE session_id=? LIMIT 500";	 Catch:{ all -> 0x005c }
        r8 = r15.rawQuery(r8, r2);	 Catch:{ all -> 0x005c }
    L_0x0018:
        r9 = r8.moveToNext();	 Catch:{ all -> 0x005a }
        if (r9 == 0) goto L_0x0052;	 Catch:{ all -> 0x005a }
    L_0x001e:
        r14.a(r8);	 Catch:{ all -> 0x005a }
        r4 = c.c.a.m0.b;	 Catch:{ all -> 0x005a }
        if (r4 == 0) goto L_0x003f;	 Catch:{ all -> 0x005a }
    L_0x0025:
        r4 = new java.lang.StringBuilder;	 Catch:{ all -> 0x005a }
        r4.<init>();	 Catch:{ all -> 0x005a }
        r9 = "queryPageInner, ";	 Catch:{ all -> 0x005a }
        r4.append(r9);	 Catch:{ all -> 0x005a }
        r4.append(r2);	 Catch:{ all -> 0x005a }
        r4.append(r0);	 Catch:{ all -> 0x005a }
        r4.append(r14);	 Catch:{ all -> 0x005a }
        r4 = r4.toString();	 Catch:{ all -> 0x005a }
        c.c.a.m0.a(r4, r5);	 Catch:{ all -> 0x005a }
    L_0x003f:
        r4 = r14.m();	 Catch:{ all -> 0x005a }
        if (r4 == 0) goto L_0x004d;	 Catch:{ all -> 0x005a }
    L_0x0045:
        r4 = r14.j();	 Catch:{ all -> 0x005a }
        r3.put(r4);	 Catch:{ all -> 0x005a }
        goto L_0x0050;	 Catch:{ all -> 0x005a }
    L_0x004d:
        r9 = r14.i;	 Catch:{ all -> 0x005a }
        r6 = r6 + r9;	 Catch:{ all -> 0x005a }
    L_0x0050:
        r4 = 1;	 Catch:{ all -> 0x005a }
        goto L_0x0018;	 Catch:{ all -> 0x005a }
    L_0x0052:
        if (r4 == 0) goto L_0x0063;	 Catch:{ all -> 0x005a }
    L_0x0054:
        r14 = "DELETE FROM page WHERE session_id=?";	 Catch:{ all -> 0x005a }
        r15.execSQL(r14, r2);	 Catch:{ all -> 0x005a }
        goto L_0x0063;
    L_0x005a:
        r14 = move-exception;
        goto L_0x005e;
    L_0x005c:
        r14 = move-exception;
        r8 = r5;
    L_0x005e:
        c.c.a.m0.b(r14);	 Catch:{ all -> 0x00b7 }
        if (r8 == 0) goto L_0x0066;
    L_0x0063:
        r8.close();
    L_0x0066:
        r14 = r3.length();
        if (r14 <= 0) goto L_0x0094;
    L_0x006c:
        r14 = 1000; // 0x3e8 float:1.401E-42 double:4.94E-321;
        r1 = (r6 > r14 ? 1 : (r6 == r14 ? 0 : -1));
        if (r1 <= 0) goto L_0x0073;
    L_0x0072:
        goto L_0x0074;
    L_0x0073:
        r6 = r14;
    L_0x0074:
        r13.i = r6;
        r1 = r12.c;
        r13.c = r1;
        r1 = r12.a;
        r13.a = r1;
        r1 = r12.a;
        r1 = r1 + r6;
        r1 = r1 / r14;
        r13.j = r1;
        r14 = r11.a;
        r14 = c.c.a.y1.a(r14);
        r13.b = r14;
        r14 = r12.e;
        r13.e = r14;
        r12 = r12.f;
        r13.f = r12;
    L_0x0094:
        r12 = c.c.a.m0.b;
        if (r12 == 0) goto L_0x00b6;
    L_0x0098:
        r12 = new java.lang.StringBuilder;
        r12.<init>();
        r14 = "queryPage, ";
        r12.append(r14);
        r12.append(r13);
        r12.append(r0);
        r13 = r3.length();
        r12.append(r13);
        r12 = r12.toString();
        c.c.a.m0.a(r12, r5);
    L_0x00b6:
        return r3;
    L_0x00b7:
        r12 = move-exception;
        if (r8 == 0) goto L_0x00bd;
    L_0x00ba:
        r8.close();
    L_0x00bd:
        throw r12;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.c.a.u.d(c.c.a.y, c.c.a.d0, c.c.a.a0, android.database.sqlite.SQLiteDatabase):org.json.JSONArray");
    }
}
